/* START: Access Key */
function getMeta(metaName) {
const metas = document.getElementsByTagName('meta');
for (let i = 0; i < metas.length; i++) {
if (metas[i].getAttribute('name') === metaName) {
return metas[i].getAttribute('content');
}
}
return '';
}
$(function () {
const accessKey = [{
// selector to check the length and determine to insert the accesskey elm
accesskeyElm: 'header',
// selector to insert before this element
insertWithIn: 'header',
// href value for
href: '#headerAccessKey',
// Access key value to press alt + in keyboard
accessKey: 'T',
// title value for
title: 'Header Access Key',
// class to be styled during focus through CSS
class: 'header-access-key',
// keyCode to set focus on keyup
keyCode: '84'
}, {
accesskeyElm: 'footer',
insertWithIn: 'footer',
href: '#footerAccessKey',
accessKey: 'B',
title: 'Footer Access Key',
class: 'footer-access-key',
keyCode: '66'
}, {
accesskeyElm: 'main',
insertWithIn: 'main',
href: '#main',
accessKey: 'C',
title: 'Main Access Key',
class: 'main-access-key',
keyCode: '67'
}, {
accesskeyElm: '.quick-links',
insertWithIn: '.quick-links',
href: '#rightAccessKey',
accessKey: 'R',
title: 'Right Access Key',
class: 'right-access-key',
keyCode: '82'
}];
/*
Below code will check the application required accesskey functionality or not
based on Meta tag.
By default it will be enabled. if the accesskey property return disabled as content then it will be disabled
*/
let allowAccessKey = true;
const readAllowAccessKeyFromAEM = getMeta('accesskey');
if (readAllowAccessKeyFromAEM === 'disabled'){
allowAccessKey = false;
}
if(allowAccessKey){
for (i = 0; i < accessKey.length; i++) {
const currItem = accessKey[i];
if ($(currItem.accesskeyElm.length).length) {
// add href, accessKey, title and class dynamically and added insertBeforeElm
const accessKeyHtml = ':::';
$(currItem.insertWithIn).prepend(accessKeyHtml);
}
}
// to attach keyup event for accesskey
document.addEventListener('keyup', function(e){
e.preventDefault();
if(e.altKey){
for (i = 0; i < accessKey.length; i++) {
const currItem = accessKey[i];
if(e.keyCode == currItem.keyCode){
const currSelector = $('.'+currItem.class);
currSelector.length ? $(currSelector).focus() : '';
break;
}
}
}
});
}
});
/* END: Access Key */
/* Adjust the Hero Banner height based on the content */
function adjustImgHeight() {
const heroImage = '.hero-banner-2023-dropdown .teaser .cmp-teaser .cmp-teaser__image .cmp-image__image';
$('.hero-banner-2023-dropdown .container:first').css({position: 'relative'});
let breadcrumbHeight = $('.hero-banner-2023-dropdown').find('.breadcrumb').outerHeight();
const contentHeight = $('.hero-banner-2023-dropdown').find('.container').outerHeight() + breadcrumbHeight;
const heroHeight = $('.hero-banner-2023-dropdown .container:first').outerHeight() + breadcrumbHeight;
$(heroImage).css('min-height', contentHeight);
if ($(heroImage).length <= 0) {
$('.hero-banner-2023-dropdown >.cmp-container').css('min-height', heroHeight);
}
$('.hero-banner-2023-dropdown .container:first').css({position: 'absolute'});
}
$( document ).ready(function() {
// On page load adjust the image height
setTimeout(function() {
adjustImgHeight();
}, 800);
adjustImgHeight();
let resizeTimer;
$(window).on('resize',function(){
clearTimeout(resizeTimer);
resizeTimer = setTimeout(function() {
adjustImgHeight();
}, 800);
});
if($('.hero-banner-2023-dropdown').find('.container').length < 2){
$('.hero-banner-2023-dropdown').addClass('topspace-teaser');
}
$(".hero-banner-2023-dropdown .custom-select .select-picker li").on( "click", function() {
setTimeout(adjustImgHeight, 1000);
});
});
// To run the method on load
$(window).on('load', function () {
stickyButton();
stickyBar();
});
// To run the method on resize
$(window).on('resize', function () {
stickyButton();
stickyBar();
});
function stickyButton() {
// sticky button offset value
let stickyButton_offset = 0;
let headerHeight = 0;
// to find the length of sticky button
if ($('.sticky-button').length) {
headerHeight = $('.aig-header.header-bar').outerHeight();
stickyButton_offset = $('.sticky-button').offset().top - headerHeight;
}
//Function to display stickyDropdown button on scroll
$(window).scroll(function () {
const stickyButton = $('.sticky-button .button');
if (stickyButton !== undefined && stickyButton.length > 0) {
if ($(window).width() < 961) {
if ($(window).scrollTop() > stickyButton_offset + headerHeight) {
stickyButton.removeClass('stick_top');}
} else {
if ($(window).scrollTop() > stickyButton_offset) {
$('.sticky-button').addClass('stick_top');
$('.sticky-button.stick_top .cmp-container').css({'top' : $('.emergencymessage').height() + $('.aig-header.header-bar').height()});
} else {
$('.sticky-button').removeClass('stick_top');
}
}
}
});
}
function stickyBar() {
// sticky bar offset value
let stickyBar_offset = 0;
let headerHeight = 0;
// to find the length of sticky bar
if ($('.sticky-bar').length) {
headerHeight = $('.aig-header.header-bar').outerHeight();
stickyBar_offset = $('.sticky-bar').offset().top - headerHeight;
}
//Function to display stickyDropdown button on scroll
$(window).scroll(function () {
const stickyBar = $('.sticky-bar .button');
if (stickyBar !== undefined && stickyBar.length > 0) {
if ($(window).width() < 961) {
if ($(window).scrollTop() > stickyBar_offset) {
$('.sticky-bar').addClass('stick_top');
$('.sticky-bar.stick_top .cmp-container').css({'top': 0+ 'px'});
}
else {
$('.sticky-bar').removeClass('stick_top');
}
} else {
if ($(window).scrollTop() > stickyBar_offset) {
$('.sticky-bar').addClass('stick_top');
$('.sticky-bar.stick_top .cmp-container').css({'top' : $('.emergencymessage').height() + $('.aig-header.header-bar').height()});
} else {
$('.sticky-bar').removeClass('stick_top');
}
}
}
});
}
$("#go-to-prev-page a").on("click", function(e){
e.preventDefault();
let prevUrl = document.referrer;
window.location.href = sanitizeText(prevUrl);
})
$("#go-to-prev-page-history a").on("click", function(e){
e.preventDefault();
history.back();
})